<?php
require "../../system/framework.php";

require_once(config::$basePath . "/system/api/simplehtmldom/simple_html_dom.php");

$contentId=$_REQUEST['content_id'];
$htmlId=$_REQUEST['html_id'];


/*
$property = new property();

$property->readProperty();


foreach (db::getData("_com_property,_com,_property", "com='map_search'") as $propertyData) {
   

   //echo $propertyData['property'];
   require config::$basePath."/code/property/{$propertyData['property']}.php";
   
   echo "value=".$property->component->$propertyData['property'];
   
   
   
}      */


/*

if (isset($_REQUEST['save_button']))
    {
        
       
        
        $domArray         =$this->dom->find("[id={$this->htmlId}]");

        foreach ($domArray as $this->component)
            {
            //$text=$item->innertext;
            //echo "TEXT:".$text;
            //echo "src".$item->src;
            //$component = $item;
            } 
        
        
        $property->component->ort = $_REQUEST['ort']; 
        

        
        exit;
        
    }






$ort = $property->component->ort; */


// falls Save
//if (isset($_REQUEST['content_id']))
if (isset($_REQUEST['save_button']))
    {

    $data=db::getDataLine("content", "id='{$_REQUEST['content_id']}'");
    //property::saveContent();

    //$text=stripslashes(request::post("text"));
    $contentOrginal=file::readTextFile($data['content_filename'], false);
    $dom=str_get_html($contentOrginal);
    //    $domArray=$dom->find("[com=text_editor]");
    $domArray=$dom->find("[id=$htmlId]");

    foreach ($domArray as $item)
        {
        //$text=$item->innertext;
        //$item->innertext=stripslashes($_REQUEST['text']);

        foreach (db::getData("_com_property,_com,_property", "com='map_search'") as $propertyData)
            {


            //echo $propertyData['property'];
            //require config::$basePath."/code/property/{$propertyData['property']}.php";

            // echo "value=".$property->component->$propertyData['property'];
            $item->$propertyData['property']=$_REQUEST["property_".$propertyData['property']];
            }
        }

    $content=$dom->save();


    /* $filename=$data['content_filename'];
       $text=request::post("content");

       $contentOrginal=file::readTextFile($filename, false);
       //$contentOrginal = dom::setTag("body", $content, $contentOrginal);
       $contentOrginal=dom::replaceInnerHtml("body", $content, $contentOrginal);*/

    file::createTextFile($data['content_filename'], $content, false);


    //$content = dom::getHtmlTags("body");
    // $content = re::getTagInnerHtml("body", $content);


    //$filename=$data['content_filename'];
    //$text=request::post("content");

    //$contentOrginal=file::readTextFile($filename, false);
    //$contentOrginal = dom::setTag("body", $content, $contentOrginal);
    //$contentOrginal=dom::replaceInnerHtml("body", $text, $contentOrginal);

    //file::createTextFile($filename, $contentOrginal, false);


    /*$content = new content();
                               //$content->title = $title;
                               //$content->url = $url;
                               $content->contentId = $data['id'];   
                               $content->text = $content;
                               /*$content->contentFilename = $filenameFrom;
                               $content->template = $template;
                               $content->header = $header;*/

    /* $content->compile = true;
     $content->createPage();   */

    /*  $compileText=new compile_text();
      //$compileText->phpScriptPath=$this->phpScriptPath;
      $compileText->codeFilename=$data['code_filename'];
      //$compileText->systemPath=$this->systemPath;
  
      $compileText->pageUrl=$data['_url'];
      $text=$compileText->compileText($content);
  
      // Body Text speichern
      //$fileName=config::$distributionPath . "/code/content/page_text_" . $codeFilename . ".php";
      file::createTextFile(config::$basePath . $data['code_filename'], $text, false);   */

    http::redirect($data['_url']);
    // exit;
    }
?>

<form id = "form1" name = "form1" enctype = "multipart/form-data" method = "post" action = "">
    <?php
    $property=new property();

    $property->readProperty();

    foreach (db::getData("_com_property,_com,_property", "com='map_search'") as $propertyData)
        {


        //echo $propertyData['property'];
        require config::$basePath . "/code/property/{$propertyData['property']}.php";

        echo "value=" . $property->component->$propertyData['property'];
        }
    ?>

    <p>
    <input type = "submit" name = "save_button" id = "save_button" value = "Senden" />
  </p>
</form>

<p>
&nbsp;</p>